/**
 * Created by qqlai on 2016/11/22.
 */
{
    angular.module('accommodationInquiryModule')
        .controller('AccommodationInquiryController', AccommodationInquiryController);
    AccommodationInquiryController.$inject = ['http.interfaces','$scope'];
    function AccommodationInquiryController(interfaces,$scope) {
        let vm = this;
        let collect = {
            inputValue: '',
            toggle: false,
            info: [],
            i: 1,
            page: 0,
            active: Active,
            search: search,
            loadList:loadList,
            moreDataCanBeLoaded:moreDataCanBeLoaded,
            logout:logout
        };
        collect.active();//进入控制器后调用一次
        vm.collect = collect;//输出集合，提供给模板调用


        /** Active方法
         * @desc 控制器触发时执行一次的方法
         * @constructor
         */
        function Active() {
        }
        
        function loadList() {
            interfaces.studentPageList({
                search_name: collect.inputValue,
                search_studentId: collect.inputValue,
                currentPage: collect.i
            }).then(res=> {
                var myData = res.data;
                collect.page = myData.pageData.pageNo;
                if (res.data.pageData.totalCount==0) {
                    collect.toggle = false;
                    alert("查无此人")
                } else {
                    collect.toggle = true;
                    collect.info=collect.info.concat(res.data.data);
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                    collect.i++;
                }
            });
        }

        function search() {
            if(collect.inputValue==''){
                alert('请输入关键字！');
            }
            else{
                collect.info=[];
                collect.i=1;
                collect.page=0;
                collect.loadList();
            }

        }

        function moreDataCanBeLoaded() {
            if (collect.i<=collect.page){
               return true;
            }
            else return false;
        }

        function logout() {
            interfaces.logout();
        }

    }
}